package com.yiyuan.weixin.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;

/**
 * Created by admin on 2017/3/24.
 * 对进来的请求进行拦截，打印
 */
public class WeiXinInFilter implements javax.servlet.Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        System.out.println(req.getRemoteHost() + " 请求时间" + req.getRequestURL() + " on " + new Date() + ".");

        System.out.println("IP:" + req.getRemoteHost());
        System.out.println("请求地址：" + req.getRequestURL()+req.getQueryString());
        for (String s : request.getParameterMap().keySet()) {
            System.out.println("请求参数："+s+"="+request.getParameterMap().get(s));
        }

//		response.getWriter().write("<HTML><BODY> Check error! <br/></BODY></HTML>");
//		response.getWriter().flush();

//        request.setCharacterEncoding(Consts.ENCODING);
//        response.setCharacterEncoding(Consts.ENCODING);
        response.setContentType("text/html;charset=UTF-8");
        filterChain.doFilter(request, response);
    }


    @Override
    public void destroy() {

    }
}
